package com.htgd.gardenexpo.controller;


import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageInfo;
import com.htgd.gardenexpo.entity.CommonResult;
import com.htgd.gardenexpo.entity.GeConIntegralGet;
import com.htgd.gardenexpo.entity.GeConIntegralGetDetails;
import com.htgd.gardenexpo.page.IntegralGetDetailsQuery;
import com.htgd.gardenexpo.page.IntegralGetQuery;
import com.htgd.gardenexpo.service.GeConIntegralGetDetailsService;
import com.htgd.gardenexpo.vo.GeConIntegralGetDetailsVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * <p>
 * 获取详情 前端控制器
 * </p>
 *
 * @author author
 * @since 2024-07-04
 */
@RestController
@RequestMapping("/api/integralGetDetails")
@Api(tags = "积分获取详情")
public class GeConIntegralGetDetailsController {

    @Autowired
    private GeConIntegralGetDetailsService geConIntegralGetDetailsService;

    @PostMapping(value = "/add")
    @ApiOperation("添加")
    public CommonResult<JSONObject> add(@RequestBody GeConIntegralGetDetails geConIntegralGetDetails) {
        CommonResult<JSONObject> result = new CommonResult<>();
        try {
            geConIntegralGetDetailsService.save(geConIntegralGetDetails);
            result.setCode(200);
            result.setMessage("添加成功");
        } catch (Exception e) {
            e.printStackTrace();
            result.setCode(500);
        }
        return result;
    }

    @PostMapping(value = "/edit")
    @ApiOperation("编辑")
    public CommonResult<JSONObject> edit(@RequestBody GeConIntegralGetDetails geConIntegralGetDetails) {
        CommonResult<JSONObject> result = new CommonResult<>();
        try {
            geConIntegralGetDetailsService.updateById(geConIntegralGetDetails);
            result.setCode(200);
            result.setMessage("编辑成功");
        } catch (Exception e) {
            e.printStackTrace();
            result.setCode(500);
        }
        return result;
    }

    @DeleteMapping(value = "/delete")
    @ApiOperation("删除")
    public CommonResult<JSONObject> delete(int id) {
        CommonResult<JSONObject> result = new CommonResult<>();
        try {
            geConIntegralGetDetailsService.removeById(id);
            result.setCode(200);
            result.setMessage("删除成功");
        } catch (Exception e) {
            e.printStackTrace();
            result.setCode(500);
        }
        return result;
    }

    @GetMapping(value = "/list")
    @ApiOperation("查询")
    public CommonResult<List<GeConIntegralGetDetails>> list(IntegralGetDetailsQuery integralGetDetailsQuery,HttpServletRequest request) {
        CommonResult<List<GeConIntegralGetDetails>> result = new CommonResult<>();
        try {
            PageInfo<GeConIntegralGetDetails> list = geConIntegralGetDetailsService.querylist(integralGetDetailsQuery,request);
            result.setCode(200);
            result.setData(list.getList());
            result.setMessage(String.valueOf(list.getTotal()));
        } catch (Exception e) {
            e.printStackTrace();
            result.setCode(500);
        }
        return result;
    }

}
